package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@ToString
@RestController
@RequestMapping("/admin/product")
public class SkuInfoController {

    @Autowired
    SkuInfoService skuInfoService;

    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){

        log.info("sku保存信息：{}",skuInfo);

        boolean b = skuInfoService.bigSaveSkuInfo(skuInfo);

        return Result.ok();
    }

     // sku的列表分页查询
    @GetMapping("/list/{page}/{limit}")
    public Result<Page<SkuInfo>> listSkuInfo(@PathVariable("page") Long page,
                                                   @PathVariable("limit") Long limit){

        Page<SkuInfo> infoPage = new Page<SkuInfo>(page,limit);

        Page<SkuInfo> skuInfoPage = skuInfoService.page(infoPage);
        return Result.ok(skuInfoPage);

    }

    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable("skuId") Long skuId){

        boolean b = skuInfoService.onSale(skuId);
        return Result.ok();

    }

    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){

        skuInfoService.cancelSale(skuId);

        return Result.ok();
    }

}
